//
//  UWGameView.h
//  Urban Words
//
//  Created by Tim Brandin on 2011-11-30.
//  Copyright (c) 2011 Sypreme. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "UWGame.h"
#import "UWGameBoard.h"
#import "PTPusher.h"
#import "PTPusherEvent.h"
#import "PTPusherChannel.h"
#import "PTPusherAPI.h"
#import "PTPusherConnection.h"
#import "UWScoreBoard.h"
#import "UWFriendManager.h"
#import "UWHistoryController.h"
#import "UWCurtain.h"

@protocol UWGameBoardDataSource;



@interface UWGameView : UIViewController <UIScrollViewDelegate, TapDetectingViewDelegate, UIAccelerometerDelegate, PTPusherPresenceChannelDelegate> {
    id <UWGameBoardDataSource>  dataSource;
    UIView                      *online_indicator;
    BOOL                        isLoadedOnce;
    UIBarButtonItem             *clearButton;
    UIBarButtonItem             *sendButton;
    UWHistoryController       *friendViewController;
    
    CGSize                      tileSize;
    UWGameBoard                 *gameBoard;

    int                         resolution;
    int                         maximumResulution;
    int                         minimunResulution;
    int                         step;
    NSTimer                     *timer;
    NSMutableArray              *tiles;
    BOOL                        isShuffeling;
    
    // Pusher
    NSMutableArray              *connectedClients;
    NSMutableArray              *memberIDs;
    
    int firstVisibleRow, firstVisibleColumn, lastVisibleRow, lastVisibleColumn;
}

@property (nonatomic, assign) id <UWGameBoardDataSource> dataSource;
@property (nonatomic, assign) UWGameBoard *gameBoard;
@property (retain, nonatomic) IBOutlet UIView *historyTableContainer;
@property (retain, nonatomic) IBOutlet UWCurtain *curtain;

@property (retain, nonatomic) UWGame *game;
@property (retain, nonatomic) IBOutlet UIScrollView *board_view;
@property (retain, nonatomic) UWScoreBoard *scoreBoard;
@property (retain, nonatomic) NSTimer *timer;
@property (retain, nonatomic) IBOutlet UIView *panel;
@property (retain, nonatomic) NSMutableArray *tiles;
@property (retain, nonatomic) PTPusher *pusher;
@property (nonatomic, retain) PTPusherPresenceChannel *currentChannel;

// game actions
- (void)play;
- (void)pass;
- (void)clear;
- (void)swap;
- (void)shuffle;
- (void)endShuffle;

// UWApi callback functions
- (void)playLoaded:(NSData *)data;

// painting methods
- (void)reloadData;
- (void)reloadDataWithNewContentSize:(CGSize)size;
- (void)repaintWithAnimation;
- (void)repaintAnimate;
- (void)buildPanel;

// Pusher
- (void)subscribeToPresenceChannel;
- (void)handleMoveEvent:(PTPusherEvent *)event;

// other
- (CGRect)zoomRectForScale:(float)scale withCenter:(CGPoint)center;

@end



@protocol UWGameBoardDataSource <NSObject>

@optional
- (UIView *)tiledGameView:(UWGameBoard *)gameView tileForRow:(int)row column:(int)column;

@end
